package com.xxx.video.mine.activitys;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.xxx.video.R;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.commen.views.recyclerviews.RefreshRecyclerView;
import com.xxx.video.main.activitys.VideoDetailsActivity;
import com.xxx.video.mine.adapters.CommentManagementListAdapter;
import com.xxx.video.mine.beans.CommentListBean;
import com.xxx.video.mine.presenters.CommentManagementPresenter;
import com.xxx.video.mine.presenters.ICommentManagementView;

import butterknife.BindView;

public class CommentManagementActivity extends BaseActivity<CommentManagementPresenter> implements ICommentManagementView, BaseRecycleViewAdapter.OnItemClickListener<CommentListBean.ListBean>, RefreshRecyclerView.OnRecyclerViewRefreshOrLoadMoreListener {
    @BindView(R.id.rcv_comment_management_list)
    RefreshRecyclerView rcvCommentManagementList;
    /**
     * adapter
     */
    private CommentManagementListAdapter mCommentManagementListAdapter;
    /**
     * page
     */
    private int page = 1;

    @Override
    protected CommentManagementPresenter createPresenter() {
        return new CommentManagementPresenter(this, this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_comment_management;
    }

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setIsShowActionbarLine(true);
        setActionBarTitle(R.string.title_comment_management_activity);
    }

    @Override
    public void initData(Bundle extras) {
        getPresenter().getCommentList(page);
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }

    @Override
    public void initData2View(CommentListBean successOb) {
        rcvCommentManagementList.resetState();
        showRootLayoutStatus(1);
        if (mCommentManagementListAdapter == null) {
            rcvCommentManagementList.setLayoutManager(new LinearLayoutManager(this));
            mCommentManagementListAdapter = new CommentManagementListAdapter(this);
            rcvCommentManagementList.setAdapter(mCommentManagementListAdapter);
            mCommentManagementListAdapter.setOnItemClickListener(this);
            rcvCommentManagementList.setOnRecyclerViewRefreshOrLoadMoreListener(this);
        }
        if (page == 1) {
            mCommentManagementListAdapter.setData(successOb.page.list);
            if (ListUtils.isEmpty(successOb.page.list)) {
                showRootLayoutStatus(2);
            }
        } else {
            mCommentManagementListAdapter.addData(successOb.page.list);
        }

    }

    @Override
    public void onItemClick(CommentListBean.ListBean listBean, int position, int type) {
        startVideoDetailsActivity(listBean.fContentId);
    }

    @Override
    public void startVideoDetailsActivity(String id) {
        Bundle bundle = new Bundle();
        bundle.putString("Id", id);
        intent2Activity(VideoDetailsActivity.class, bundle);
    }

    @Override
    public void onRecyclerviewRefresh() {
        page = 1;
        getPresenter().getCommentList(page);
    }

    @Override
    public void onRecyclerviewLoadMore() {
        page++;
        getPresenter().getCommentList(page);
    }
}
